package com.jcl.recruit.console.mapper;

import com.jcl.recruit.console.model.ConsoleUserToken;
import com.jcl.recruit.console.mapper.provider.ConsoleUserTokenProvider;
import com.jcl.recruit.mapper.SqlMapper;
import com.jcl.recruit.mapper.provider.SqlProvider;
import org.apache.ibatis.annotations.*;

/**
 * @ClassName ConsoleUserTokenMapper
 * @Author yyliu
 * @Date 2018/12/13 16:45
 * @Version 1.0
 **/
public interface ConsoleUserTokenMapper extends SqlMapper {

    String TABLE_NAME = "t_user_token";

    @Select({
            SQL_QUERY
    })
    ConsoleUserToken findOne(@Param("corpCode") String corpCode,
                             @Param("userId") Integer userId);

    @Update({
            SQL_UPDATE
    })
    int updateToken(@Param("corpCode") String corpCode,
                    @Param("userId") Integer userId,
                    @Param("token") String token);

    @InsertProvider(type = ConsoleUserTokenProvider.class, method = SqlProvider.SQL_METHOD_INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(ConsoleUserToken entity);

    @UpdateProvider(type = ConsoleUserTokenProvider.class, method = SqlProvider.SQL_METHOD_UPDATE)
    int update(ConsoleUserToken entity);


    String SQL_QUERY = "select * from " + TABLE_NAME + " where corp_code = #{corpCode} and user_id = #{userId} ";
    String SQL_UPDATE = "update " + TABLE_NAME
            + " set token = #{token} where corp_code = #{corpCode} and user_id = #{userId} ";

}
